
<template>
  <div class="app-container">
    <el-tabs v-model="activeName">
      <el-tab-pane label="我的评审任务" name="first">
        <el-form :model="queryParams" ref="form" size="small" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="小组名称" prop="groupName">
            <el-input v-model="queryParams.groupName" placeholder="请输入专利名称" clearable
              @keyup.enter.native="handleQuery" />
          </el-form-item>
          <el-form-item label="小组类型" prop="groupType">
            <el-input v-model="queryParams.groupType" placeholder="请输入专利上传人" clearable
              @keyup.enter.native="handleQuery" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
        <el-table :data="taskGroup" style="width: 100%">
          <el-table-column type="expand">
            <template slot-scope="props">
              <el-table :data="props.row.projectList" style="backgr">
                <el-table-column label="专利编号" prop="id" align="center" width="100"></el-table-column>
                <el-table-column label="专利名称" prop="proName" align="center"></el-table-column>
                <el-table-column label="专利文件" align="center">
                  <template slot-scope="scope">
                    <a @click="downloadFile(scope.row)" class="fileStyle">{{downName(scope.row.proFile)}}</a>
                    <el-progress :percentage="progress1" :format="format" v-if="scope.row.id == rowid ? true : false">
                    </el-progress>
                  </template>
                </el-table-column>
                <el-table-column label="专利作者" prop="proAuthor" align="center"></el-table-column>
                <el-table-column label="创建时间" :formatter="dateFormat" prop="proCreatetime" align="center">
                </el-table-column>
                <el-table-column label="评审分数" prop="score" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                  <template slot-scope="scope">
                    <el-button type="success" v-if="scope.row.score==''||scope.row.score==null"
                      @click="handReview(scope.row)">专利评分
                    </el-button>
                    <el-button type="danger" v-else disabled>已完成评审</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </template>
          </el-table-column>
          <el-table-column label="小组编号" prop="groupId" align="center">
          </el-table-column>
          <el-table-column label="小组名称" prop="groupName" align="center">
          </el-table-column>
          <el-table-column label="小组类型" prop="proType" align="center">
          </el-table-column>
        </el-table>
        <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
          @pagination="getListGroup" />
      </el-tab-pane>
      <!-- 通过审核数据面板 -->
    </el-tabs>
    <!-- 添加或修改用户配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form">
        <el-row>
          <el-col :span="24">
            <div class="demonstration" style="margin-top: -30px;">专利名称：<span>{{form.proName}}</span>
            </div>
            <div class="demonstration">专利作者：<span>{{form.proAuthor}}</span></div>
            <div class="demonstration">专利类型：<span>{{form.proType}}</span></div>
            <div class="demonstration">专利描述：<span>{{form.proDescr}}</span></div>
            <el-divider></el-divider>
          </el-col>
          <el-col :span="4" style="font-weight:600">评分细则</el-col>
          <el-col :span="18">
            <el-row>
              <el-col :span="4" class="scorex">60</el-col>
              <el-col :span="4" class="scorex">70</el-col>
              <el-col :span="4" class="scorex">80</el-col>
              <el-col :span="4" class="scorex">90</el-col>
              <el-col :span="5" class="scorex">100</el-col>
            </el-row>
          </el-col>
          <el-col :span="2">得分</el-col>
          <!-- BEGIN -->
          <el-col :span="24" style="margin-top:30px">
            <!-- 指标1 -->
            <el-row>
              <el-col :span="5">{{norm1[0]}}</el-col>
              <el-col :span="14">
                <el-radio-group v-model="radiofrom.radio1" @change="changeX1">
                  <el-radio :label="6" style="margin-left:5px">{{text}}</el-radio>
                  <el-radio :label="7" style="margin-left:18px">{{text}}</el-radio>
                  <el-radio :label="8" style="margin-left:15px">{{text}}</el-radio>
                  <el-radio :label="9" style="margin-left:15px">{{text}}</el-radio>
                  <el-radio :label="10" style="margin-left:25px">{{text}}</el-radio>
                </el-radio-group>
              </el-col>
              <el-col :span="5">
                <div style="width:170px;text-align:center" v-if="isNaN(radiofrom.value1*10)==false">
                  {{radiofrom.value1*10}}</div>
                <div style="width:170px;text-align:center" v-else>暂无评分</div>
              </el-col>
            </el-row>
            <!-- 指标2 -->
            <el-row style="margin-top:20px">
              <el-col :span="5">{{norm1[1]}}</el-col>
              <el-col :span="14">
                <el-radio-group v-model="radiofrom.radio2" @change="changeX2">
                  <el-radio :label="6" style="margin-left:5px">{{text}}</el-radio>
                  <el-radio :label="7" style="margin-left:18px">{{text}}</el-radio>
                  <el-radio :label="8" style="margin-left:15px">{{text}}</el-radio>
                  <el-radio :label="9" style="margin-left:15px">{{text}}</el-radio>
                  <el-radio :label="10" style="margin-left:25px">{{text}}</el-radio>
                </el-radio-group>
              </el-col>
              <el-col :span="5">
                <div style="width:170px;text-align:center" v-if="isNaN(radiofrom.value2*10)==false">
                  {{radiofrom.value2*10}}</div>
                <div style="width:170px;text-align:center" v-else>暂无评分</div>
              </el-col>
            </el-row>
            <!-- 指标3 -->
            <el-row style="margin-top:20px">
              <el-col :span="5">{{norm1[2]}}</el-col>
              <el-col :span="14">
                <el-radio-group v-model="radiofrom.radio3" @change="changeX3">
                  <el-radio :label="6" style="margin-left:5px">{{text}}</el-radio>
                  <el-radio :label="7" style="margin-left:18px">{{text}}</el-radio>
                  <el-radio :label="8" style="margin-left:15px">{{text}}</el-radio>
                  <el-radio :label="9" style="margin-left:15px">{{text}}</el-radio>
                  <el-radio :label="10" style="margin-left:25px">{{text}}</el-radio>
                </el-radio-group>
              </el-col>
              <el-col :span="5">
                <div style="width:170px;text-align:center" v-if="isNaN(radiofrom.value3*10)==false">
                  {{radiofrom.value3*10}}</div>
                <div style="width:170px;text-align:center" v-else>暂无评分</div>
              </el-col>
            </el-row>
            <!-- 指标4 -->
            <el-row style="margin-top:20px">
              <el-col :span="5">{{norm1[3]}}</el-col>
              <el-col :span="14">
                <el-radio-group v-model="radiofrom.radio4" @change="changeX4">
                  <el-radio :label="6" style="margin-left:5px">{{text}}</el-radio>
                  <el-radio :label="7" style="margin-left:18px">{{text}}</el-radio>
                  <el-radio :label="8" style="margin-left:15px">{{text}}</el-radio>
                  <el-radio :label="9" style="margin-left:15px">{{text}}</el-radio>
                  <el-radio :label="10" style="margin-left:25px">{{text}}</el-radio>
                </el-radio-group>
              </el-col>
              <el-col :span="5">
                <div style="width:170px;text-align:center" v-if="isNaN(radiofrom.value4*10)==false">
                  {{radiofrom.value4*10}}</div>
                <div style="width:170px;text-align:center" v-else>暂无评分</div>
              </el-col>
            </el-row>
            <!-- 指标5 -->
            <el-row style="margin-top:20px">
              <el-col :span="5">{{norm1[4]}}</el-col>
              <el-col :span="14">
                <el-radio-group v-model="radiofrom.radio5" @change="changeX5">
                  <el-radio :label="6" style="margin-left:5px">{{text}}</el-radio>
                  <el-radio :label="7" style="margin-left:18px">{{text}}</el-radio>
                  <el-radio :label="8" style="margin-left:15px">{{text}}</el-radio>
                  <el-radio :label="9" style="margin-left:15px">{{text}}</el-radio>
                  <el-radio :label="10" style="margin-left:25px">{{text}}</el-radio>
                </el-radio-group>
              </el-col>
              <el-col :span="5">
                <div style="width:170px;text-align:center" v-if="isNaN(radiofrom.value5*10)==false">
                  {{radiofrom.value5*10}}</div>
                <div style="width:170px;text-align:center" v-else>暂无评分</div>
              </el-col>
            </el-row>
            <!-- END -->
          </el-col>
          <el-col :span="24">
            <el-divider></el-divider>
            <el-col :span="16">
              <div style="text-align:right;line-height:35px" v-if="isNaN(this.radiofrom.result)==false"> 平均总分：<span
                  style="color:orange" v-text="(this.radiofrom.result/5)"></span>
              </div>
              <div style="text-align:right;line-height:35px" v-else>
                平均总分：
                <span style="color:orange">未完成</span>

              </div>
            </el-col>
            <el-col :span="8">
              <div style="text-align:right">
                <el-button type="info" @click="clear">重置</el-button>
                <el-button type="success" @click="pushTo">提交</el-button>
              </div>
            </el-col>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
    <!-- 阅读须知 -->
    <el-dialog title="评审需知" :visible.sync="dialogVisible2" width="60%">
      <div style="text-indent:24px">
        各位专家：
        <br>
        <div style="text-indent:24px;margin-top:20px">
          (一)维护评审成果所有者的知识产权，保守被评审专利的技术秘密。评审工作完成后，不得向其他组织或者个人扩散有关评审成果的所有材料，不得非法占有、使用、提供、转让。
        </div>
        <div style="text-indent:24px;margin-top:20px">

          (二)自觉坚持回避原则，不接受邀请参加与评价成果有利益关系或可能影响公正性的评价。
        </div>
        <div style="text-indent:24px;margin-top:20px">
          (三)要根据评审评分指标体系要求以及填报的专利内容逐项予以评分，给出每项指标得分，最后计算合计得分。
        </div>
        <div style="text-indent:24px;margin-top:20px">
          (四)不得收受除约定的咨询费之外的任何组织、个人提供的与评审有关的酬金、有价物品或其他好处。
        </div>

      </div>
      <div style="margin-top:20px;">
        <el-radio v-model="radio" label="1" style="font-weight:900">已阅读并同意以上条款</el-radio>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible2 = false">取 消</el-button>
        <el-button type="primary" @click="handX">确 定</el-button>
      </span>
    </el-dialog>

  </div>
</template>

<script>
import download from "@/plugins/download"
import { selectScore } from "@/api/system/project/projectData";
import { listPost } from '@/api/system/post'
import { selectTask, updataScore } from "@/api/system/project/project";
import { listNorm } from "@/api/system/project/norm";

import moment from "moment";

export default {
  name: "ProjectData",
  data () {
    return {
      value1: 0,
      radio: '',
      activeName: 'first',
      radiofrom: {
        radio1: 0,
        radio2: 0,
        radio3: 0,
        radio4: 0,
        radio5: 0,
        value1: 0,
        value2: 0,
        value3: 0,
        value4: 0,
        value5: 0,
        result: 0
      },
      // 遮罩层
      loading: true,
      statusText: "",
      text: '',
      // 选中数组
      ids: [],
      texts: ["4", "8", "12", "16", "20"],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 专利数据表格数据
      projectDataList: [],
      // 指标数据
      norm: [],
      norm1: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      dialogVisible2: false,
      groupList: '',
      taskGroup: [],
      rowid: '',
      listPost: [],
      progress1: 0,
      ruleForm: {
        value1: null,
        value2: null,
        value3: null,
        value4: null,
        value5: null,
        result: null
      },
      // 查询参数
      queryParams: {
        groupName: null,
        proAuthor: null,
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      examineList: [],
      adoptList: [],
      reject: []
    };
  },
  created () {
    this.getNorm()
    this.getListGroup()
    this.changeX1()
    this.changeX2()
    this.changeX3()
    this.changeX4()
    this.changeX5()
  },
  computed: {
    progress () {
      return this.$store.state.myProject.progress;
    },
  },
  watch: {
    progress (newval, oldval) {
      this.progress1 = newval;
    },
  },
  methods: {
    handX () {
      if (this.radio != 1) {
        this.$message.error("请先阅读评分须知并同意")
      } else {
        this.dialogVisible2 = false
        this.open = true
      }
    },
    //获取指标信息
    getNorm () {
      listNorm().then(res => {
        this.norm = res.rows
        this.norm.map(item => {
          this.norm1.push(item.name)
        })
      })
    },
    //时间格式化
    dateFormat: function (row, column) {
      var date = row[column.property];
      if (date == undefined) {
        return "";
      }
      return moment(date).format("YYYY-MM-DD HH:mm");
    },

    changeX1 (value) {
      this.radiofrom.value1 = value
      this.getResult()
    },
    changeX2 (value) {
      this.radiofrom.value2 = value
      this.getResult()

    },
    changeX3 (value) {
      this.radiofrom.value3 = value
      this.getResult()

    },
    changeX4 (value) {
      this.radiofrom.value4 = value
      this.getResult()

    },
    changeX5 (value) {
      this.radiofrom.value5 = value
      this.getResult()

    },
    getResult () {
      this.radiofrom.result = this.radiofrom.value1 * 10 + this.radiofrom.value2 * 10 + this.radiofrom.value3 * 10 + this.radiofrom.value4 * 10 + this.radiofrom.value5 * 10
    },
    reset () {
      this.form = {
        id: null,
        proName: null,
        proFile: null,
        proType: null,
        proDescr: null,
        proAuthor: null,
        proCreatetime: null,
        proGroupStatus: 0,
        groupId: null,
        score: "",
        userId: null,
        status: 0
      };
      this.resetForm("form");
    },
    pushTo () {
      if (isNaN(this.radiofrom.result) == true) {
        alert("您还没有指标没有评分！")
      } else {
        this.$confirm('是否确认提交当前评审结果，提交后无法修改', {
          confirmButtonText: '提交',
          cancelButtonText: '取消',
          type: 'success'
        }).then(() => {
          this.form.score = this.radiofrom.result / 5
          updataScore(this.form).then(res => {
            this.$message({
              type: 'success',
              message: '提交成功'
            })
            this.open = false
            this.getListGroup()
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          });
        })

      }
    },
    clear () {
      this.radiofrom = {
        radio1: null,
        radio2: null,
        radio3: null,
        radio4: null,
        radio5: null,
        result: null
      }
    },
    submitForm (formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert('submit!');
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },

    getListGroup () {
      selectTask().then(res => {
        this.List = res.rows
        let dataInfo = [];
        this.List.forEach((item, index) => {
          let { groupName, groupId, proType } = item;
          if (!dataInfo[groupId]) {
            dataInfo[groupId] = {
              groupId,
              groupName,
              proType,
              projectList: []
            }
          }
          dataInfo[groupId].projectList.push(item);
        });
        this.taskGroup = Object.values(dataInfo);

        listPost().then(res => {
          this.listPost = res.rows
          for (var i = 0; i < this.taskGroup.length; i++) {
            for (var j = 0; j < this.listPost.length; j++) {
              if (this.taskGroup[i].proType == this.listPost[j].postId) {
                this.taskGroup[i].proType = (this.listPost[j].postName).substring(0, this.listPost[j].postName.length - 2)
              }
            }

          }
        })
        this.total = this.taskGroup.length;
      })
    },
    format (percentage) {
      return percentage === 100 ? "完成" : `${percentage}%`;
    },
    downloadFile (data) {
      if (this.progress1 != 0) {
        this.$message({
          message: "已经有一个专利正在下载",
          type: "warning",
        });
      } else {
        this.rowid = data.id;
        download.resource(data.proFile);
        setTimeout(() => {
          this.rowid = "";
          this.progress1 = 0;
        }, 3000);
      }
    },
    downName (file) {
      let data = file.split("/");
      return data[data.length - 1];
    },
    /** 查询专利数据列表 */

    // 取消按钮
    cancel () {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset () {
      this.form = {
        id: null,
        proAuthor: null,
        groupName: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1;
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handReview (row) {
      this.dialogVisible2 = true
      /** 修改按钮操作 */
      this.reset();
      const id = row.id || this.ids;
      selectScore(id).then(response => {
        this.form = response.data;
        this.title = "指标评审";
      });
    },

  }
};
</script>
<style scoped>
.scorex {
  text-align: center;
  font-weight: 600;
}
.fileStyle {
  padding: 12px;
  color: #442ed0;
}
.fileStyle:hover {
  text-decoration: underline !important;
  cursor: pointer;
  color: #2300ff;
}
.demonstration {
  line-height: 50px;
}
.demonstration > span {
  color: rgb(255, 145, 0);
}
.score {
  text-align: right;
}
</style>
